package cn.edu.sziit.bbs.service;

import cn.edu.sziit.bbs.dao.PostMapper;
import cn.edu.sziit.bbs.model.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PostService {

    @Autowired
    private PostMapper postMapper;

    /**
     * 插入post
     *
     * @param post
     */
    public void insert(Post post) {
        postMapper.insertSelective(post);
    }

    /**
     * 查询所有帖子
     *
     * @return
     */
    public List<Post> selectAll() {
        return postMapper.selectAll();
    }

    /**
     * 根据postId查询post
     *
     * @param postId
     * @return
     */
    public Post selectByPrimaryKey(Integer postId) {
        return postMapper.selectByPrimaryKey(postId);
    }

    /**
     * 根据postId删除post
     *
     * @param postId
     * @return
     */
    public String deleteByPrimaryKey(Integer postId) {
        postMapper.deleteByPrimaryKey(postId);
        return "删除帖子成功";
    }

    /**
     * 根据userId查询post
     *
     * @param userId
     * @return
     */
    public List<Post> selectAllByUserId(Integer userId) {
        return postMapper.selectAllByUserId(userId);
    }

    /**
     * 根据帖子标题模糊查询帖子
     *
     * @param postTitle
     * @return
     */
    public List<Post> selectAllByPostTitle(String postTitle) {
        return postMapper.selectAllByPostTitle(postTitle);
    }

}
